package com.cotte.flow.controller;

import com.cotte.flow.service.GraphTableService;
import com.cotte.flow.util.ServiceResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Date;

/**
 * Created by zhuang on 2018/12/28.
 */
@RestController
@RequestMapping("/graph_workhour")
public class GraphTableController {

    @Autowired
    private GraphTableService graphTableService;

    @GetMapping("/line")
    public ServiceResult<ArrayList, String> loadGraphTable(String key,String start, String end){
        ArrayList res = null;
        if(!key.isEmpty()){
            res = graphTableService.lineData(key,start,end);
        }
        return ServiceResult.success(res);
    }

    @GetMapping("/update")
    public ServiceResult<String,String> update(String key,String workhours,String records){
        if(!key.isEmpty()) {
            graphTableService.updateRow(key, workhours, records);
        }
        return ServiceResult.success("UPDATE");
    }

    @GetMapping("/countDay")
    public ServiceResult<String,String> countDay(String time){
        graphTableService.countDayData(new Date(new Long(time)));
        return ServiceResult.success("COUNTDAY");
    }

    @GetMapping("/countAll")
    public ServiceResult<String,String> count(String isall){
        graphTableService.countAllData(isall);
        return ServiceResult.success("COUNT");
    }
}
